<html>
<head><meta charset="utf-8"><title>size_of::&lt;Waker&gt;() · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/size_of.3A.3A.3CWaker.3E().html">size_of::&lt;Waker&gt;()</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212826907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/size_of%3A%3A%3CWaker%3E%28%29/near/212826907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sean McArthur <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/size_of.3A.3A.3CWaker.3E().html#212826907">(Oct 09 2020 at 13:42)</a>:</h4>
<p>I wanted to check if we'd consider the size of a <code>std::task::Waker</code> guaranteed to be the same size forever, and so could document that guarantee.</p>
<p>For background, I'm making a C API for hyper, and need to expose a <code>Waker</code>. So far, I box them and expose <code>*mut Waker</code>, which in some ways is unfortunate, capturing a waker happens somewhat frequently, and at the moment it's to box a 2-pointer-sized value into 1 pointer. If the size will never ever change, and we put that in the docs, then I could instead expose some <code>struct hyper_waker { void *_opaque[2]; }</code>. I don't think the size of a struct is usually something someone can rely on in Rust, as implementation details can change, so I'm not strongly for this. I figured I'd check now, while still designing hyper's C API.</p>



<a name="212827155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/size_of%3A%3A%3CWaker%3E%28%29/near/212827155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sean McArthur <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/size_of.3A.3A.3CWaker.3E().html#212827155">(Oct 09 2020 at 13:44)</a>:</h4>
<p>Another thing I notice is that there is <code>#[repr(transparent)]</code> on <code>Waker</code>, claiming it wraps a <code>RawWaker</code>. And the docs for <code>RawWaker</code> claims it "consists of a data pointer and vtable". However, I also note that that doesn't necessarily mean that's <em>all</em> it could ever consist of.</p>



<a name="212832184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/size_of%3A%3A%3CWaker%3E%28%29/near/212832184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/size_of.3A.3A.3CWaker.3E().html#212832184">(Oct 09 2020 at 14:23)</a>:</h4>
<p><span class="user-mention" data-user-id="243965">@Sean McArthur</span> I think the way I'd go about getting this confirmed is to open a PR against rust-lang/rust std/core with the change to documentation that would require this guarantee and then we can FCP that with T-libs</p>



<a name="212832264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/size_of%3A%3A%3CWaker%3E%28%29/near/212832264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/size_of.3A.3A.3CWaker.3E().html#212832264">(Oct 09 2020 at 14:24)</a>:</h4>
<p>(We could also guarantee it's "no more than 4 pointers" or something like that, to give us some breathing room)</p>



<a name="212859341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/size_of%3A%3A%3CWaker%3E%28%29/near/212859341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/size_of.3A.3A.3CWaker.3E().html#212859341">(Oct 09 2020 at 18:18)</a>:</h4>
<p>Agreed with <span class="user-mention" data-user-id="116122">@simulacrum</span> on how to go about this. I think it has a pretty good chance of succeeding.</p>



<a name="213062793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/size_of%3A%3A%3CWaker%3E%28%29/near/213062793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> comex <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/size_of.3A.3A.3CWaker.3E().html#213062793">(Oct 12 2020 at 16:58)</a>:</h4>
<p>On a related note, I'd like the ability to retrieve the data and vtable pointers from a Waker/RawWaker.  That way, I could 'downcast' by comparing the vtable to known pointers.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>